package com.licq.ldoc.parser.impl.annotation;

import java.lang.annotation.Annotation;

import net.sf.oval.constraint.MinSize;

import com.licq.ldoc.domain.AbstractNode;
import com.licq.ldoc.domain.Occurrencies;
import com.licq.ldoc.parser.AnnotationParsee;
import com.licq.ldoc.parser.impl.TargetIgnorableAnnotationParsee;

public class MinSizeAnnotationParsee extends TargetIgnorableAnnotationParsee {
	
	public MinSizeAnnotationParsee(AnnotationParsee successor) {
		super(successor);
	}

	@Override
	protected void doParseTo(AbstractNode node, Annotation annotation) {
		//the node must be collection, array or wraped by these, orelse the oval check will fail.
		MinSize minSize = (MinSize) annotation;
		int minSizeValue = minSize.value();
		Occurrencies occurrences = node.getOccurrences();
		if (occurrences.getLeast() < minSizeValue) {
			occurrences = occurrences.clone();
			occurrences.setLeast(minSizeValue);
			node.setOccurrences(occurrences);
		}
	}
	
}
